package cn.tedu.ex;

import java.io.*;

//测试
//jdk1.7 --try-with-resources：自动关闭流--自动资源管理
public class TestIO {
    public static void main(String[] args)  {
        method();
        method2();
    }

    public static void method2() {

        try(InputStream in=new BufferedInputStream(new FileInputStream("d:\\iotest\\14.txt"))) {
            int b= 0;
            b = in.read();
            System.out.println("b = " + b);
        }catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void method()  {
        InputStream in = null;
        try {
            in=new BufferedInputStream(new FileInputStream("d:\\iotest\\14.txt"));
            int b= 0;
            b = in.read();
            System.out.println("b = " + b);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
        e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
